<script type="text/javascript">
	//获取菜单树
	function returnMenuTree() {
		var data;
		$.ajax({
			url : "sys/res/menuMgr",
			type : "post",
			dataType : "json",
			data : {
				action : 'menuTree'
			},
			success : function(e) {
				data = e;
			},
			async : false
		});
		//return [{"id":1,"pid":0,"faicon":"rss","faiconClose":"cab","name":"表单元素","level":0,"tId":"menuTree_1","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":true,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":10,"pid":1,"url":"form-button.html","tabid":"form-button","faicon":"bell","pId":1,"name":"按钮","level":0,"tId":"menuTree_2","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":11,"pid":1,"url":"form-input.html","tabid":"form-input","faicon":"info-circle","pId":1,"name":"文本框","level":0,"tId":"menuTree_3","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":12,"pid":1,"url":"form-select.html","tabid":"form-select","faicon":"ellipsis-v","pId":1,"name":"下拉选择框","level":0,"tId":"menuTree_4","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":13,"pid":1,"url":"form-checkbox.html","tabid":"table","faicon":"soccer-ball-o","pId":1,"name":"复选、单选框","level":0,"tId":"menuTree_5","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":14,"pid":1,"url":"form.html","tabid":"form","faicon":"comments","pId":1,"name":"表单综合演示","level":0,"tId":"menuTree_6","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":2,"pid":0,"name":"表格","level":0,"tId":"menuTree_7","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":20,"pid":2,"url":"table.html","tabid":"table","faicon":"signal","pId":2,"name":"普通表格","level":0,"tId":"menuTree_8","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":21,"pid":2,"url":"table-fixed.html","tabid":"table-fixed","faicon":"rss-square","pId":2,"name":"固定表头表格","level":0,"tId":"menuTree_9","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":false,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false},{"id":22,"pid":2,"url":"table-edit.html","tabid":"table-edit","faicon":"bookmark-o","pId":2,"name":"可编辑表格","level":0,"tId":"menuTree_10","parentTId":null,"open":false,"isParent":false,"zAsync":true,"isFirstNode":false,"isLastNode":true,"isAjaxing":false,"checked":false,"checkedOld":false,"nocheck":false,"chkDisabled":false,"halfCheck":false,"check_Child_State":-1,"check_Focus":false,"isHover":false,"editNameFlag":false}]
		return data;
	}
	
	//处理表格行点击事件
	function onRowCick(userId) {
		if(userId){
			//设置用户id
			$.CurrentNavtab.find("#userId").val(userId);
			//向后台请求用户的菜单数据
			var mx = ajaxJsonSync("sys/user/userMenuMgr",{action:"getUserLeafMenuId",userId:userId});
			//清空菜单树的勾选
			var tree = $.fn.zTree.getZTreeObj("userMenuTree");
			tree.checkAllNodes(false);
			if(mx){
				for(var i=0; i<mx.length; i++){
					var id = mx[i];
					var node = tree.getNodesByParam("id",id,null);
					tree.checkNode(node[0],true,false);
				}
			}
		}
		return true;
	}
	//保存用户的菜单权限配置
	function onSaveUserMenu(){
		//获取用户Id
		var userId = $.CurrentNavtab.find("#userId").val();
		if(userId){
			//获取树上选择的节点信息
			var tree = $.fn.zTree.getZTreeObj("userMenuTree");
			var nodes = tree.getCheckedNodes(true);
			//获取Id数组
			var ids = new Array();
			for(var i=0; i<nodes.length; i++){
				ids.push(nodes[i].id);
			}
			//发送数据到后台进行保存
			var r = ajaxJsonSync("sys/user/userMenuMgr",{action:"saveUserMenu",userId:userId,menuId:ids.toString()});
			$(this).alertmsg("info",r.message);
		}else{
			$(this).alertmsg("warn","请选择要配置的用户！");
		}
	}
</script>
<div class="bjui-pageContent  tableContent">
	<div class="tableContent" id="userList"
		style="width: 49%; float: left; height: 100%; padding: 10px;">
		<fieldset style="height: 100%; overflow: auto;">
			<legend>用户列表</legend>
			<div style="height:28px;">
				<form id="pagerForm" data-toggle="ajaxsearch"
					action="sys/user/userMenuMgr?action=mgr" method="post">
					<input type="hidden" name="pageSize" value="${pager.pageSize}">
					<input type="hidden" name="pageCurrent"
						value="${pager.pageCurrent}">
					<input type="hidden" name="orderField" value="${pager.orderField}">
					<input type="hidden" name="orderDirection"
						value="${pager.orderDirection}">
					<div class="bjui-searchBar">
						<label>登录名：</label>
						<input type="text" id="userCode"
							value="${pager.params.userCode!''}" name="userCode"
							class="form-control" size="10">
						&nbsp;
						<label>用户姓名：</label>
						<input type="text" value="${pager.params.userName!''}"
							name="userName" class="form-control" size="10">
						<button type="submit" class="btn-default" data-icon="search">查询</button>
						&nbsp;
						<button id="queryBtn" type="button" class="btn-orange"
							data-toggle="reloadsearch" data-clear-query="true">清空查询</button>
					</div>
				</form>
			</div>
			<div style="height:88%">
				<table style="height:100%" data-width="100%" class="table table-bordered">
					<thead>
						<tr>
							<th width="80" data-order-field="userCode">登录名</th>
							<th width="80" data-order-field="userName">用户姓名</th>
							<th width="130" data-order-field="idCard">身份标识</th>
						</tr>
					</thead>
					<tbody>
						<#list pager.pageData.list as u>
						<tr onclick="onRowCick(${u.id})" data-id="${u.id}">
							<td height="24px;">${u.userCode}</td>
							<td height="24px;">${u.userName}</td>
							<td height="24px;">${u.idCard}</td>
						</tr>
						</#list>
						<tr  height="100%;"><td colspan="3">&nbsp;</td></tr>
					</tbody>
					<TFOOT>
						<tr style="height:32px;">
						<td colspan="3">
						<#include "/WEB-INF/html/common/pager.html">
						</td>
						</tr>
					</TFOOT>
				</table>
			</div>
		</fieldset>
	</div>
	<div style="padding: 1%; width: 49%; float: left; height: 100%;">
		<input type="hidden" id="userId"/>
		
		<fieldset style="height: 100%; overflow: auto;">
			<legend>用户菜单</legend>
			<a class="btn btn-info" style="float:right;" onclick="onSaveUserMenu();">保存配置</a>
			<div
				style="float: left; width: 86%; height: 95%; overflow: auto;">
				<ul id="userMenuTree" class="ztree" data-toggle="ztree"
					data-options="{
                        expandAll: true,
                        checkEnable:true,
                        nodes:'returnMenuTree'
                    }">
				</ul>
			</div>
		</fieldset>
	</div>
</div>